package service;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.Socket;

/**
 * @author: hett
 * @date: 2022/3/14 11:22
 */
public class FakeHandleThread extends Thread{

    private Socket socket;

    private BufferedInputStream bis = null;

    public Socket getSocket() {
        return socket;
    }

    public void setSocket(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            byte[] bytes = new  byte[2];
            StringBuilder message = new StringBuilder();
            bis = new BufferedInputStream(socket.getInputStream());
            while ((bis.read(bytes)) !=-1){
                message.append(new String(bytes));
                if (bis.available() ==0){
                    System.out.println(message);
                    message.delete(0, message.length());
                }
            }
            if ((bis.read(bytes) == -1)){
                System.out.println("用户离开");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
